package net.example.lesson2;


public class StringTest {
    /**
     *
     */
    public static void terst1(){
        long start = System.currentTimeMillis();
        String str = "abc";
        for (int i=0;i<100000;i++){
            str += i+""+i+i;
        }
        long end = System.currentTimeMillis();

        System.out.println(end-start);

        start = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer("abc");
        for (int i=0;i<100000;i++){
            sb.append(i).append(i).append(i);
        }
        end = System.currentTimeMillis();

        System.out.println(end-start);
    }

    public static void terst2(){
        long start = System.currentTimeMillis();
        for (int i=0;i<1000000;i++){
            String str = "abc" + "def" + "ght";
        }
        long end = System.currentTimeMillis();

        System.out.println(end-start);

        start = System.currentTimeMillis();
        for (int i=0;i<1000000;i++){
            StringBuffer sb = new StringBuffer("abc").append("def").append("ght");
        }
        end = System.currentTimeMillis();

        System.out.println(end-start);
    }

    public static void terst3(){
        long start = System.currentTimeMillis();
        String str = "abc" + "def" + "ght";
        long end = System.currentTimeMillis();

        System.out.println(end-start);
    }
    public static void terst4(){
        long start = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<10000000;i++){
            sb.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
    public static void terst5(){
        long start = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer();
        for (int i=0;i<10000000;i++){
            sb.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }

    public static void main(String[] args) {
        terst4();
        terst5();
    }
}
